/*
 * Factory.cpp
 *
 *  Created on: 2014. 3. 21.
 *      Author: zenoniaonline
 */

#include "../User.h"

namespace ProjectZ {

User::Factory::Factory()
{
	pPool = new NUtil::Pool<User>(3000);
}

User::Factory::~Factory()
{
	delete pPool;
}

User *
User::Factory::NEW()
{
	User * pUser = pPool->NEW();
	return pUser;
}

bool
User::Factory::DEL(User * pUser)
{
	DEBUGLOG("USERPOOL DEL REF COUNT : %d GID : %d", pUser->GetRefCount(), pUser->GetUserSeq());
	if (0 >= pUser->GetRefCount())
	{
		// log
		::Logger::GETLOG()->ToAll(::Logger::OBSERVER, "----------------------------------------------------");
		::Logger::GETLOG()->ToAll(::Logger::OBSERVER, "USERPOOL if (0 >= pUser->GetRefCount()) GID : %d", pUser->GetUserSeq());
		pUser->RewindState();
		pUser->RewindEnumState();
		::Logger::GETLOG()->ToAll(::Logger::OBSERVER, "----------------------------------------------------");

		return false;
	}

//	::Logger::GETLOG()->ToAll(::Logger::OBSERVER, "----------------------------------------------------");
//	pUser->RewindState();
//	pUser->RewindEnumState();
//	::Logger::GETLOG()->ToAll(::Logger::OBSERVER, "----------------------------------------------------");


	if (0 == pUser->SubRefCount())
	{
		DEBUGLOG("USERPOOL DEL RELEASE GID : %d", pUser->GetUserSeq());
		pPool->DEL(pUser);
		return true;
	}

	return false;
}

} /* namespace ProjectZ */


